package com.ftg.shopping.memberlogin.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ftg.shopping.config.LayuiPage;
import com.ftg.shopping.member.entity.sp_memberinfo;
import com.ftg.shopping.memberlogin.mapper.MemberLoginMapper;
import com.ftg.shopping.user.entity.sp_userinfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;


@Service
public class MemberLoginService {

    @Autowired
    MemberLoginMapper memberLoginMapper;


    public LayuiPage<sp_memberinfo> login(sp_memberinfo m) {

        IPage<sp_userinfo> ip = new Page<>();
        LayuiPage member = new LayuiPage<>(ip);
        QueryWrapper qw = new QueryWrapper();
        Map<String, Object> map = new HashMap<>();
        map.put("userid", m.userid);
        map.put("password", m.password);
        qw.allEq(map, false);
        if (memberLoginMapper.selectList(qw).isEmpty()) {
            member.setStatus("failure");
            return member;
        } else {
            member.setStatus("success");
            member.setData(memberLoginMapper.selectList(qw));
            return member;
        }

    }
    public int savememberlogin(sp_memberinfo m){
       Map<String,Object> map= memberLoginMapper.showmember(m);
       if(map==null||map.isEmpty()){
           return memberLoginMapper.insert(m);
       }else{
           return 0;
       }

    }


}
